<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace redis;

class redis {

    protected $redis;

    function __construct() {
        //连接 Redis 服务
        $this->redis = new \redis();
        $this->redis->connect('47.98.198.195', 9736);
        $this->redis->auth('heyiwei');
    }

    //list  
    function redis_set($key, $val, $time = 0) {
        if ($time > 0) {
            $rs = $this->redis->setex($key, $time, $val);
        } else {
            $rs = $this->redis->set($key, $val);
        }
        return $rs;
    }

    function redis_get($key) {
        $rs = $this->redis->get($key);
        return $rs;
    }

    function del_key($key) {
        return $this->redis->delete($key);
    }

    function flushAll() {
        return $this->redis->flushAll();
    }

    function __destruct() {
        $this->redis->close();
    }

}
